package com.keepers.repair.activity;

import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;

import com.keepers.repair.R;
import com.keepers.repair.helper.RxHelper;
import com.keepers.repair.utils.ThemeUtils;
import com.to.aboomy.statusbar_lib.StatusBarUtil;

/**
 * auth aboom
 * date 2018/10/21
 */
public class BaseActivity extends AppCompatActivity {

    public RxHelper rxHelper = RxHelper.getHelper();

    public boolean isImmersiveStatusBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            isImmersiveStatusBar = StatusBarUtil.setImmersiveStatusBarBackgroundColor(this, ThemeUtils.getThemeAttrColor(this, R.attr.colorPrimary));
        }
    }

    /**
     * 设置状态栏透明，需要在onCreate之后调用
     */
    public void transparencyBar() {
        if (isImmersiveStatusBar && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            StatusBarUtil.transparencyBar(this, ThemeUtils.getThemeAttrColor(this, R.attr.colorPrimary));
        }
    }

    @SuppressWarnings("unchecked")
    public <T extends View> T ff(int id) {
        return (T) LayoutInflater.from(this).inflate(id, null);
    }

    @SuppressWarnings("unchecked")
    public <T extends View> T f(int id) {
        return (T) findViewById(id);
    }

    @SuppressWarnings("unchecked")
    public <T extends View> T f(View view, int id) {
        return (T) view.findViewById(id);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        rxHelper.onDestroy();
    }
}
